package com.bienvenue.main.ui.activity.enterprise;

import android.content.Intent;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.util.SparseArray;
import android.view.View;
import android.widget.RadioGroup;

import com.bienvenue.main.R;
import com.bienvenue.main.adapter.HomeFragmentPagerAdapter;
import com.bienvenue.main.base.BaseActivity;
import com.bienvenue.main.httpService.ResponseObserver;
import com.bienvenue.main.model.HttpBean;
import com.bienvenue.main.model.LoginBean;
import com.bienvenue.main.serviceApi.ServiceModel;

import com.bienvenue.main.ui.fragment.enterprise.EnterpriseMainFragment;
import com.bienvenue.main.ui.fragment.enterprise.EnterpriseMeFragment;
import com.bienvenue.main.ui.fragment.enterprise.EnterpriseMessageFragment;
import com.bienvenue.main.weight.ViewPagerFixed;

import org.zackratos.ultimatebar.UltimateBar;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * @ProjectName: Bienvenue
 * @Package: com.bienvenue.main.ui.activity
 * @ClassName: EnterpriseMainActivity
 * @Description: 企业主页
 * @Author: Mr.Chen
 * @CreateDate: 2020/9/15 14:08
 * @UpdateUser: Mr.Chen
 * @UpdateDate: 2020/9/15 14:08
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */


public class EnterpriseMainActivity extends BaseActivity implements ViewPager.OnPageChangeListener{
    @BindView(R.id.bn_bottom_bar)
    BottomNavigationView bnBottomBar;
    @BindView(R.id.contentViewPager)
    ViewPagerFixed contentViewPager;

    String token;

    private EnterpriseMainFragment mainFragment;
    private List<Fragment> mFragmentList = new ArrayList<>(4);

    @Override
    protected void initData() {
//        ServiceModel.getServiceModel().searchWebApp("装潢", 1, 4, 19, new ResponseObserver<HttpBean>() {
//            @Override
//            public void onSuccess(HttpBean response) {
//                Log.e("TAG",response.getMessage());
//            }
//
//            @Override
//            public void onFail(String message) {
//                Log.e("TAG",message);
//
//            }
//        });

//        ServiceModel.getServiceModel().setImg("storage/emulated/0/DCIM/Screenshots/Screenshot_2020-09-01-23-40-35-843_com.ss.android.ugc.aweme.jpg", new ResponseObserver<HttpBean>() {
//            @Override
//            public void onSuccess(HttpBean response) {
//                Log.e("TAG",response.getMessage());
//            }
//
//            @Override
//            public void onFail(String message) {
//                Log.e("TAG",message);
//
//            }
//        });


    }

    @Override
    protected void initView() {
        bnBottomBar.setItemIconTintList(null);
        //设置ViewPager的最大缓存页面
        contentViewPager.setOffscreenPageLimit(3);
        mainFragment = new EnterpriseMainFragment();
        mFragmentList.add(mainFragment);
        mFragmentList.add(new EnterpriseMessageFragment());
        mFragmentList.add(new EnterpriseMeFragment());
        contentViewPager.setAdapter(new HomeFragmentPagerAdapter(getSupportFragmentManager(), mFragmentList));
        contentViewPager.setOnPageChangeListener(this);

        bnBottomBar.setOnNavigationItemSelectedListener(item -> {
            switch (item.getItemId()) {
                case R.id.main:
                    contentViewPager.setCurrentItem(0);
                    break;
                case R.id.message:
                    contentViewPager.setCurrentItem(1);
                    setTitle("消息");
                    break;
                case R.id.me:
                    contentViewPager.setCurrentItem(2);
                    setTitle("我的");
                    break;
                default:
                    break;
            }
            return true;
        });
    }

    @Override
    protected int getLayoutId() {
        UltimateBar ultimateBar = new UltimateBar(this);
        ultimateBar.setColorBar(ContextCompat.getColor(this, R.color.color_4959FF));
        return R.layout.activity_enterprise_main;
    }

    @Override
    public void onPageScrolled(int i, float v, int i1) {

    }

    @Override
    public void onPageSelected(int position) {
        switch (position) {
            case 0:
                bnBottomBar.setSelectedItemId(R.id.main);
                break;
            case 1:
                bnBottomBar.setSelectedItemId(R.id.message);
                break;
            case 2:
                bnBottomBar.setSelectedItemId(R.id.me);
                break;

            default:
                break;
        }
    }

    @Override
    public void onPageScrollStateChanged(int state) {
        if (state != ViewPager.SCROLL_STATE_IDLE) {
            //滚动过程中隐藏快速导航条
//            contactListFragment.showQuickIndexBar(false);
        } else {
//            contactListFragment.showQuickIndexBar(true);
        }
    }

}
